package cn.itcast.obj;

import cn.itcast.util.BackGround;
import cn.itcast.util.StaticValue;

import java.awt.image.BufferedImage;

public class DaoJu implements Runnable{
    //存储当前坐标
    private int x;
    private int y;
    //存储道具类型
    private int type;
    //用于显示道具当前图像
    private BufferedImage show;
    //定义一个背景对象
    private BackGround bg;
    //定义线程对象
    private Thread thread = new Thread(this);
    //定义当前图片状态
    private int image_type = 0;

    public DaoJu() {
    }

    //蘑菇道具构造参数
    public DaoJu(int x, int y, int type, BackGround bg) {
        this.x = x;
        this.y = y;
        this.type = type;
        this.bg = bg;
        show = StaticValue.mogu.get(0);
        thread.start();
    }


    //吃道具方法
    public void eat(){
        this.bg.getDaoJuList().remove(this);
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getType() {
        return type;
    }

    public BufferedImage getShow() {
        return show;
    }

    @Override
    public void run() {
        while (true) {
            //判断道具类型
            if (type == 0) {
                image_type = image_type == 1 ? 0 : 1;
                show = StaticValue.mg.get(image_type);
            }

            //判断是否是小花道具
            if (type == 1) {
                show = StaticValue.xh;
            }

            //判断是否是金币道具
            if (type == 2) {
                image_type = image_type == 1 ? 0 : 1;
                show = StaticValue.jinBi.get(image_type);
            }

            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
